package com.test.datatemp;

import com.alibaba.fastjson.JSONObject;
import com.test.testbaen.TestBean;
import exam.demo.Test;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/4/14 15:24
 * @since JDK 1.8
 */
public class DataTempDemo {

    public static void main(String[] args) {
        Test();
    }

    public static void Test(){
        List<TestBean> testList=new ArrayList<>();
        for (int i = 0; i < 1000 ; i++) {
            TestBean testBean=new TestBean();
            testBean.setId(i);
            testBean.setName("小红"+i);
            testList.add(testBean);
        }
        String str=JSONObject.toJSONString(testList);
        File file=new File("C:\\Users\\xiong\\Desktop\\789\\567.txt");
        System.out.println(file.getParent());
        IoUtils.writeTxtFile(str,file);
    }

    public static void Test2(File file){
        if(!file.exists()){
            file.mkdirs();
        }
        String str=IoUtils.txt2String(file);
        System.out.println(str);
        List<TestBean> testBeans=JSONObject.parseArray(str,TestBean.class);
        testBeans.stream().forEach(e->{
            System.out.println(e);
        });
    }


}
